import utils from './util.js';

const httpRequest = (data) => {
	//获取ip
	let serverIp = utils.getStor('connectData') || '';

	//访问地址
	let baseUrl = 'http://' + serverIp + ':8081/command';

	// console.log(serverIp,'serverIp');
	let httpDefaultOpts = {
		url: baseUrl,
		data: data,
		method: 'post',
		dataType: 'json',
		header: {
			'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
		}
	}
	
	let promise = new Promise(function(resolve, reject) {
		
		// uni.showLoading({
		// 	title: '请稍候...',
		// 	mask: true //是否显示透明蒙层，防止触摸穿透，默认false
		// })
		
		uni.request(httpDefaultOpts)
			.then((res) => {
				// console.log(res,'请求结果')
				// uni.hideLoading();
				resolve(res[1])
			})
			.catch((error) => {
				// uni.hideLoading();
				reject(error)
			})
	})
	return promise
};


export default {
	httpRequest
}
